package com.taobao.dao.impl;

import java.util.HashMap;
import java.util.Map;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.taobao.dao.CommonSerDao;
import com.taobao.dao.UserInfoDao;
import com.taobao.pojo.Config;
import com.taobao.pojo.HttpContext;
import com.taobao.pojo.UserInfo;

public class UserInfoSerDaoImpl extends CommonSerDao implements UserInfoDao {

    @Override
    public UserInfo getUserInfo() throws Exception {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("AUserName", Config.userName);
        return (UserInfo) postRequest("UserData", param);
    }

    @Override
    public Object process(HttpContext context) throws Exception {
        UserInfo userInfo = new UserInfo();
        Document doc = Jsoup.parse(context.getHtml());
        Elements es = doc.getElementsByTag("user");
        Element ele = es.get(0);
        userInfo.setUserName(Config.userName);
        userInfo.setMoney(ele.getElementsByTag("price").text());
        userInfo.setpPoint(ele.getElementsByTag("fbd").text());
        userInfo.setIntegral(ele.getElementsByTag("integral").text());
        userInfo.setLevel(ele.getElementsByTag("level").text());
        userInfo.setWarning(ele.getElementsByTag("warningNum").text());
        return userInfo;
    }
}
